package cn.com.common.job.task;

import java.util.List;

import org.quartz.DisallowConcurrentExecution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import cn.com.common.constants.Constants;
import cn.com.system.entity.SysDept;
import cn.com.system.service.DeptService;
import cn.com.thirdparty.entity.VExXzqhEntity;
import cn.com.thirdparty.service.VExXzqhService;


/**
 * 定时任务(演示Demo，可删除) testTask为spring bean的名称， 方法名称必须是run
 *
 * @author wenbin
 * @version V1.0
 * @date 2020年3月18日
 */
@Component("gasVExXzqhProcessTask")
@DisallowConcurrentExecution
public class GasVExXzqhProcessTask {
	
	@Value("${gasstation.timedTask.gasVExXzqhProcessTask}")
	private String gasVExXzqhProcessTask;
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private VExXzqhService vExXzqhService;
	@Autowired
	private DeptService deptService;
	
	public void run(String params) throws Exception {
		logger.debug("gasVExXzqhProcessTask定时任务正在执行，参数为：{}", params);
		
		logger.debug("application参数为gasVExXzqhProcessTask：{}", gasVExXzqhProcessTask);

		if (gasVExXzqhProcessTask.equals(Constants.JOB_STOP)) {

			logger.debug("application配置文件控制不执行gasVExXzqhProcessTask定时任务");
			throw new Exception("application配置文件控制不执行gasVExXzqhProcessTask定时任务");
		
		}
		
		List<SysDept> list = deptService.list();
		// List<VExXzqhEntity> _list = new ArrayList<>();
		
		for (SysDept sysDept : list) {
			VExXzqhEntity vExXzqh = new VExXzqhEntity();
			
			vExXzqh.setXzqhDm(sysDept.getId().substring(1,7));
			vExXzqh.setXzqhMc(sysDept.getManagerName());
			
			vExXzqhService.saveVExXzqh(vExXzqh);
		}
		
	}
	
}
